package com.myboot.demo.utils;


import com.myboot.demo.enums.CodeEnum;

/**
 * @Author: 韦溜溜
 * @Description:
 * @Date: Create in 16:30 2019/1/5
 */
public class EnumUtil {
    /**
     * 根据枚举对应的code来返回一个枚举对象
     * @param code
     * @param enumClass
     * @param <T>
     * @return
     */
    public static <T extends CodeEnum> T getBycode(Integer code , Class<T> enumClass){
        for(T each: enumClass.getEnumConstants()){
            if(code.equals(each.getCode()))
                return each;
        }
        return null;
    }
}
